#pragma once

#include "hash.h"

template<typename K>
class HashFunc;

namespace byh
{
	template<typename K, typename Hash = HashFunc<K>>
	class unordered_set
	{
		struct KeyOfSet
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};

	public:
		using iterator = typename hash_bucket::HashTable<K, const K, KeyOfSet, Hash>::iterator;
		using const_iterator = typename hash_bucket::HashTable<K, const K, KeyOfSet, Hash>::const_iterator;

		iterator begin()
		{
			return _hash_table.begin();
		}

		iterator end()
		{
			return _hash_table.end();
		}

		const_iterator begin() const
		{
			return _hash_table.begin();
		}

		const_iterator end() const
		{
			// const unordered_set*
			return _hash_table.end();
		}

		pair<iterator, bool> insert(const K& key)
		{
			return _hash_table.insert(key);
		}

	private:
		hash_bucket::HashTable<K, const K, KeyOfSet, Hash> _hash_table;
	};

	void Print(const unordered_set<int>& s)
	{
		unordered_set<int>::const_iterator it = s.begin();
		while (it != s.end())
		{
			cout << *it << " ";
		}
		cout << endl;
	}

	void Test_Set()
	{
		unordered_set<int> s;
		s.insert(2);
		s.insert(1);
		s.insert(3);
		s.insert(6);
		s.insert(8);
		s.insert(7);

		Print(s);

		//unordered_set<int>::iterator it = s.begin();
		//while (it != s.end())
		//{
		//	// *it = 3;
		//	cout << *it << " ";
		//	++it;
		//}
		//cout << endl;
	}
}